<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>流程处理</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
    <div class="Wrapper">
        <div>
        	<div align="left" class="btnsBox">
                <input name="processInstanceIdNm" id="processInstanceId" type="text" style="display: none;" value="${processInstanceId}"/>
                <input name="taskIdNm" id="taskId" type="text" style="display: none;" value="${taskId}"/>
                <input name="assignableIdNm" id="assignableId" type="text" style="display: none;" value="${assignable}"/>
                <input name="formUrlIdNm" id="formUrlId" type="text" style="display: none;" value="${formUrl}"/>
                <input name="processDefinitionIdNm" id="processDefinitionId" type="text" style="display: none;" value="${processDefinitionId}"/>
                <input name="processDefinitionKeyIdNm" id="processDefinitionKeyId" type="text" style="display: none;" value="${processDefinitionKey}"/>
                <input name="taskDefKeyIdNm" id="taskDefKeyId" type="text" style="display: none;" value="${taskDefKey}"/>
                <input name="flowPicUrlIdNm" id="flowPicUrlId" type="text" style="display: none;" value="${flowPicUrl}"/>
                <input name="businessKeyIdNm" id="businessKeyId" type="text" style="display: none;" value="${businessKey}"/>
                <input name="taskTypeIdNm" id="taskTypeId" type="text" style="display: none;" value="${taskType}"/>
                <input name="taskStatusIdNm" id="taskStatusId" type="text" style="display: none;" value="${taskStatus}"/>
                <input name="assigneeIdNm" id="assigneeId" type="text" style="display: none;" value="${assignee}"/>
            	<input name="originTaskIdNm" id="originTaskId" type="text" style="display: none;" value="${originTaskId}"/>
            </div>
            <div id="pageInTab" class="pageInTab">
                <div tabid="tabA" title="任务处理" lselected="true">
                    <div id="div_flow_task_info_h_id"></div>
                </div>
                <div tabid="tabB" title="附加信息">
                    <iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
                </div>
                <div tabid="tabC" title="流程跟踪">
                    <iframe frameborder="0" name="tabC" id="tabC" src=""></iframe>
                </div>
            </div>
        </div>
    </div>

    <script>
    var pageInApp={}; // to 下一级子窗口 接口
    var pageInTab=null;
    var loadedTabs=[]
    $(function() {
    	initTab();
    	initFlowTaskInfoH();
    });
    
    //初始化流程历史节点信息
    function initFlowTaskInfoH(){
    	var _taskId = $("#taskId").val();
    	var _processDefinitionId = $("#processDefinitionId").val();
    	var _processInstanceId = $("#processInstanceId").val();
    	var _originTaskId = $("#originTaskId").val();
    	var parms = {
    			taskId:_taskId,
    			processDefinitionId:_processDefinitionId,
    			processInstanceId:_processInstanceId,
    			originTaskId:_originTaskId
    	}
    	var _url = '<%=path%>/flow/flow/initFlowTaskInfoListWithNext.do';
	   	 AjaxUtils.ajaxGet(_url, parms, function(msg){
	   		 if(msg.success == 1 && msg.data){
                 msg.data = SqHTMLDecodeObj(msg.data);
				 var html = "<div class=\"sectionBox\"><div class=\"recordTask\">";//sectionBox start
    			  $.each(msg.data, function (n, value) {
    				  html+='<div class=\"recordBox\">'//recordBox start
    				  	  //这里做个处理,要是结束节点则不显示操作人
    				  	  var content = value.taskTm + ' [' + value.opUsrNm + ']' + value.opRlNm;
    				  	  if(FlowConstant.FLOW_TASK_ACTIVITY_TYPE_END == value.activityType){
    				  		content = "";//清空
    				  	  }
    				  	 var taskNm = "";
    				  	 if(StringUtils.isNotEmpty(value.taskName)){
      				  		taskNm = value.taskName + "->"; 
      				  	  }
     	                  html+='<div class=\"rcTit\">' + content + ' : '+ taskNm + value.outgoingFlow + '</div>';
    	                  html+="<div class=\"rcBody\">";//rcBody start
    	                  
    	                  //html+='<div>' + value.taskOpinion + '</div>';
    	                  
    	                  if(StringUtils.isNotEmpty(value.taskOpinion) && value.taskOpinion != "null"){
    	   	                  	html+='<div>' + value.taskOpinion + '</div>';
    	   	              }else{
    	   	               		html+='<div>&nbsp;</div>';
    	   	              }
    	                  
    	                  //判断是否有附件,如果有则加入附件
    	                  html+="<div>";//div 1 start
    	                  if(value.attchmntList){
    	                	  $.each(value.attchmntList, function (nt, valuet) {
    	                			//判断是否是图片,如果是图片则加入target属性
     	                		  	if(StringUtils.isNotEmpty(valuet.filePath)){
     	                		  		html+="&nbsp;&nbsp;&nbsp;&nbsp;";
     	                		  		try
	  		   	                		{
	  		   	                		  	var extStart=valuet.filePath.lastIndexOf(".");
	  	   	                		    	var ext=valuet.filePath.substr(extStart,valuet.filePath.length).toUpperCase();
	  	   	                		    	if(SQ.regs.img.test(ext)){
	  	   	                		    		html+='<a class="fileLink" role="winOpen" href="javascript:openImgWin(';
	  			   	                		 	html+="'"+valuet.filePath+"'";
	  			   	                			html+=",'"+valuet.fileNm+"'";
	  			   	                			html+=')">'+valuet.fileNm+'</a>';
	  	   	                		    	}else{
	  	   	                		    		html+="<a target='_blank' class='fileLink' href='"+valuet.filePath+"'>"+valuet.fileNm+"</a>";
	  	   	                		    	}
	  		   	                		}
	  		   	                		catch(err)
	  		   	                		{
	  		   	                			html+="<a class='fileLink' target='_blank' href='"+valuet.filePath+"'>"+valuet.fileNm+"</a>";
	  		   	                		}
     	                		  	}
	    	                  });
    	                  }
    	                  html+="</div>";//div 1 end
    	                  html+="</div>";//rcBody end
    	                  html+='</div>';//recordBox end
    			  });
    			  html+='</div></div>';//sectionBox end
    			  $("#div_flow_task_info_h_id").empty();
    			  $("#div_flow_task_info_h_id").html(html);
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		 },true);
    }
    
    //初始化Tab页
    function initTab(){
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onAfterSelectTabItem: function(tabid) {
                if (loadedTabs.indexOf(tabid)<0) {
                    loadedTabs.push(tabid);
                   	var domain = "<%=path%>";
                	var _formUrl = $("#formUrlId").val();
                	var _businessKey = $("#businessKeyId").val();
                	if(StringUtils.isNotEmpty(_formUrl)){
                		_formUrl = domain + _formUrl + _businessKey;
                	}
                    switch (tabid){
                        case "tabB":
                        	pageInTab.setTabItemSrc(tabid, _formUrl);
                            break;
                        case "tabC":
                        	var flowPicURL = $("#flowPicUrlId").val();
                            pageInTab.setTabItemSrc(tabid, flowPicURL);
                            break;
                    }
                };
                SetIframe_height();
            }
        });
        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });
    }
    
    //打开通用图片显示窗口
	function openImgWin(_url,_name){
		if(SQ.regs.img.test(_name)){
         	window.__ImgSrc = _url;
         	window.__ImgTit = _name;
         	window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
		}else{
	        window.open(_url);
		}
    }
    </script>
</body>
</html>